package org.jeecg.modules.ncmeapis.network.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import ncme.digital.hszy.common.typeHandler.LogicDeleteHandler;

@Data
@TableName(value = "network_file", autoResultMap = true)
public class NetworkFile {

    @TableId(value = "id", type = IdType.AUTO)
    protected Integer id;

    //"文件上传时的原始名称，用于前端浏览文件名、下载时命名用及下载时的文件类型获取")
    @TableField(value = "`origin_name`")
    private String originName;

    //"在存储中的名字，下载或预览时用")
    @TableField(value = "`store_name`")
    private String storeName;

    //"服务名，用于目录分级")
    @TableField(value = "`service`")
    private String service;

    //"存储类型，用于目录分级")
    @TableField(value = "`type`")
    private String type;

    //"文件的MD5,用于做闪存功能")
    @TableField(value = "`md5`")
    private String md5;

    //"是否上传完成")
    @TableField(value = "`complete`")
    private Boolean complete;

    //"是否是链接,闪存功能字段")
    @TableField(value = "`is_link`")
    private Integer isLink;

    //"实际文件id,当该文件为闪存类型时有效,闪存功能字段")
    @TableField(value = "`link_id`")
    private Integer linkId;

    //"文件大小")
    @TableField(value = "`size`")
    private Long size;

    //"是否有效，避免软删除后闪存文件无法查询")
    @TableField(value = "`is_active`")
    private Integer isActive;

    @TableLogic
    @TableField(value = "is_deleted", typeHandler = LogicDeleteHandler.class)
    protected boolean isDeleted = false;

    @Version
    @TableField(value = "version")
    protected Integer version;

    /**
     * 在闪存情景下，如果已存在文件则使用该构造
     */
    public NetworkFile(NetworkFile networkFile, String originName, String service, String type) {
        this.originName = originName;
        this.storeName = networkFile.getStoreName();
        this.service = service;
        this.type = type;
        this.md5 = networkFile.getMd5();
        this.isLink = 1;
        this.linkId = networkFile.getId();
        this.size = networkFile.getSize();
        this.isActive = 1;
    }

    /**
     * 切片上传时使用
     */
    public NetworkFile(String originName, String storeName, String service, String type, String md5, Long size) {
        this.originName = originName;
        this.storeName = storeName;
        this.service = service;
        this.type = type;
        this.md5 = md5;
        this.isLink = 0;
        this.linkId = -1;
        this.size = size;
        this.isActive = 1;
    }

}
